﻿@model ConferenceNewsModel
@{
	ViewBag.Title = Resources.ConferenceNews + ConstValues.strDash + ViewBag.ConferenceName;
}
<div id="menuBar" style="height:35px;">
	<div style="float: left; padding: 5px 5px; font-weight: bold; text-align: left;">
		@Resources.NewsTitle：<input id="selNewsTitle" class="easyui-textbox" style="height:27px; width:200px;" />&nbsp;&nbsp;
		<a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-search" onclick="searchData();">@Resources.Search</a>&nbsp;&nbsp;
		@if ((User as ICISPrincipal).IsSSA || (User as ICISPrincipal).CSAList.Contains(Model.ConferenceId) || Utility.HasConferenceRole((User as ICISPrincipal), Model.ConferenceId, ConstValues.FunctionId.ConferenceNews, RoleType.添加))
		{
			<a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-add" onclick="addData();" plain="true">@Resources.Create</a>
		}
	</div>
	<div class="clear"></div>
</div>
<div id="dataGrid"></div>

@section bodyParts {
<div id="detailWindow" class="easyui-window"
	title="@Resources.ConferenceNews" data-options="closed:true,minimizable:false,maximizable:false,iconCls:'icon-save'"
	style="width:1200px; height:800px; display:none;">
	<div class="main">
		<div class="box clearfix">
			<h3 id="detailWindowTitle" class="tit01">@Resources.Create</h3>
			<form id="frmDetail" method="post" enctype="multipart/form-data">
				@Html.AntiForgeryToken()
				<table width="100%" height="100%" id="tblDetail" cellpadding="0" cellspacing="1" border="0" class="tastyle01">
					<tr>
						<td style="text-align: right;" class="w1 c1">@Resources.ConferenceName：</td>
						<td style="text-align: left;" class="w2 c2">
							<input id="hidID" name="Id" type="hidden" />
							<input id="hidConferenceId" name="ConferenceId" type="hidden" />
							<input id="txtConferenceName" disabled class="easyui-textbox" style="height:27px; width:300px;" value="@ViewBag.ConferenceName">
						</td>
						<td style="text-align: right;" class="w1 c1">@Resources.NewsTitle：</td>
						<td style="text-align: left;" class="w2 c2">
							<input id="txtNewsTitle" name="NewsTitle" class="easyui-textbox" style="height:27px; width:300px;" data-options="required:true,validType:['length[1,100]']">
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c3">@Resources.NewsListName：</td>
						<td style="text-align: left;" class="w2 c4">
							<input id="txtNewsListName" name="NewsListId" class="easyui-combobox" style="height:27px; width:300px;" data-options="">
						</td>
						<td style="text-align: right;" class="w1 c3">@Resources.IsRecommend：</td>
						<td style="text-align: left;" class="w2 c4">
							<select id="ddlIsRecommend" name="IsRecommend" class="easyui-combobox" style="height:27px; width:300px;" data-options="editable:false,panelHeight:'auto'">
								<option value="@ConstValues.GenericSelectionType.有">@Resources.Yes</option>
								<option value="@ConstValues.GenericSelectionType.无">@Resources.No</option>
							</select>
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c1">@Resources.IsTop：</td>
						<td style="text-align: left;" class="w2 c2">
							<select id="ddlIsTop" name="IsTop" class="easyui-combobox" style="height:27px; width:300px;" data-options="editable:false,panelHeight:'auto'">
								<option value="@ConstValues.GenericSelectionType.有">@Resources.Yes</option>
								<option value="@ConstValues.GenericSelectionType.无">@Resources.No</option>
							</select>
						</td>
						<td style="text-align: right;" class="w1 c1">@Resources.IsShowInMobile：</td>
						<td style="text-align: left;" class="w2 c2">
							<select id="ddlIsShowInMobile" name="IsShowInMobile" class="easyui-combobox" style="height:27px; width:300px;" data-options="editable:false,panelHeight:'auto'">
								<option value="@ConstValues.GenericSelectionType.有">@Resources.Yes</option>
								<option value="@ConstValues.GenericSelectionType.无">@Resources.No</option>
							</select>
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c3">@Resources.ShowTime：</td>
						<td style="text-align: left;" class="w2 c4">
							<input id="showTime" name="ShowTime" class="easyui-datebox" style="height:27px; width:300px;" data-options="editable:false">
						</td>
						<td style="text-align: right;" class="w1 c3">@Resources.Link：</td>
						<td style="text-align: left;" class="w2 c4">
							<input id="txtLink" name="Link" class="easyui-textbox" style="height:27px; width:300px;" data-options="validType:['length[1,100]']">
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c1">@Resources.SimplePic：</td>
						<td style="text-align: left;" class="w2 c2" colspan="3">
							<input id="txtSimplePic" name="SimplePic" class="easyui-filebox" style="height:27px; width:84%;" data-options="prompt:'@Resources.ImportImg', buttonText:'@Resources.ChooseImg', accept: 'image/jpeg,image/png,image/gif'">
							<input type="hidden" id="hidSimplePic" name="SimplePicPath" />
							<a href="javascript:void(0)" class="easyui-linkbutton" onclick='$("#txtSimplePic").filebox("clear"); $("#hidSimplePic").val("");'>@Resources.Clear</a>
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c3">@Resources.MainPic：</td>
						<td style="text-align: left;" class="w2 c4" colspan="3">
							<input id="txtMainPic" name="MainPic" class="easyui-filebox" style="height:27px; width:84%;" data-options="prompt:'@Resources.ImportImg', buttonText:'@Resources.ChooseImg', accept: 'image/jpeg,image/png,image/gif'">
							<input type="hidden" id="hidMainPic" name="MainPicPath" />
							<a href="javascript:void(0)" class="easyui-linkbutton" onclick='$("#txtMainPic").filebox("clear"); $("#hidMainPic").val("");'>@Resources.Clear</a>
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c1">@Resources.Keyword：</td>
						<td style="text-align: left;" class="w2 c2" colspan="3">
							<input id="txtKeyword" name="Keyword" class="easyui-textbox" style="height:27px; width:88%;" data-options="">
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c3">@Resources.Abstract：</td>
						<td style="text-align: left;" class="w2 c4" colspan="3">
							<input type="hidden" id="txtAbstract" name="Abstract" />
							<div class="grid-container">
								<div class="grid-width-100" style="padding-left:0%;padding-right:0%;width:88%;">
									<textarea id="editor" name="editor"></textarea>
								</div>
							</div>
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c1">@Resources.NewsEssay：</td>
						<td style="text-align: left;" class="w2 c2" colspan="3">
							<input type="hidden" id="txtNewsEssay" name="NewsEssay" />
							<div class="grid-container">
								<div class="grid-width-100" style="padding-left:0%;padding-right:0%;width:88%;">
									<textarea cols="90" rows="10" id="editorSec" name="editorSec"></textarea>
								</div>
							</div>
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c3">@Resources.Status：</td>
						<td style="text-align: left;" class="w2 c4">
							<select id="ddlStatus" name="Status" class="easyui-combobox" style="height:27px; width:300px;" data-options="editable:false,required:true,panelHeight:'auto'">
								<option value="@ConstValues.Status.正常">@Resources.Normal</option>
								<option value="@ConstValues.Status.暂停">@Resources.Pause</option>
							</select>
						</td>
						<td style="text-align: right;" class="w1 c3">@Resources.Sort：</td>
						<td style="text-align: left;" class="w2 c4">
							<input id="txtSort" name="Sort" class="easyui-numberbox" style="height:27px; width:300px;" />
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c1">@Resources.Remark：</td>
						<td style="text-align: left;" class="w2 c2" colspan="3">
							<input id="txtRemark" name="Remark" class="easyui-textbox" style="height:50px; width:88%;" data-options="multiline:true,validType:['length[1,1000]']" />
						</td>
					</tr>
				</table>
			</form>
			<div class="btnDiv">
				<input type="hidden" id="hdnWindowType" />
				<input type="button" class="gbtn" onclick="saveData();" value="@Resources.Save" />&nbsp;&nbsp;
				<input type="button" class="rbtn" onclick="$('#detailWindow').window('close');" value="@Resources.Cancel" />
			</div>
		</div>
	</div>
</div>
}

@section Scripts {
<script>
	common.setCurrentMenu("ConferenceNews");
	common.setCurrentParentMenu("#menu_a5");

	var windowWidth = $(window).width() - 285;
	var windowHeight = $(window).height() - 110;

	var language = "@ViewBag.Language";
	if (language == "@ConstValues.Language.Cn") {
		CKEDITOR.config.language = "zh-cn";
	} else {
		CKEDITOR.config.language = "en";
	}

	initSample();
	$(function () {
		$("#hidConferenceId").val("@Model.ConferenceId");
		$("#selNewsTitle").textbox("textbox").bind("keydown", function (e) {
			if (e.keyCode == 13) {
				searchData()
			}
		});

		ckeditor = CKEDITOR.replace("editorSec");
		CKFinder.setupCKEditor(ckeditor,"~/Scripts/ckfinder/")
		$("#dataGrid").datagrid({
			url: "@Url.Action(nameof(ConferenceNewsController.GetData),
					nameof(ConferenceNewsController).GetControllerName(),new { ConferenceId = Model.ConferenceId })",
			method: "get",
			singleSelect: true,
			width: $(window).width() - 285,
			height: $(window).height() - 158,
			nowrap: false,
			pagination: true,
			pageSize: @ConstValues.DefaultGridRows,
			striped: true,
			pageSize: 100, 
			pageList: [100, 200, 300, 400, 500],
			frozenColumns: [[
				{ field: "id", title: "@Resources.Id", align: "center", hidden:true, width: 50 },
				@if ((User as ICISPrincipal).IsSSA || (User as ICISPrincipal).CSAList.Contains(Model.ConferenceId) ||
					Utility.HasConferenceRole((User as ICISPrincipal), Model.ConferenceId, ConstValues.FunctionId.ConferenceNews, RoleType.修改) ||
					Utility.HasConferenceRole((User as ICISPrincipal), Model.ConferenceId, ConstValues.FunctionId.ConferenceNews, RoleType.删除))
				{
					<text>
					{
						field: "operate", title: "@Resources.Operate", align: "center", width: 150,
						formatter: function(value, rec) {
					    		var strInfo = "";
							var tmp = rec.newsTitle == null ? "" : rec.newsTitle.replace(new RegExp("'",'g'),"’").replace(new RegExp('"','g'),"“");
					    		@if ((User as ICISPrincipal).IsSSA || (User as ICISPrincipal).CSAList.Contains(Model.ConferenceId) || Utility.HasConferenceRole((User as ICISPrincipal), Model.ConferenceId, ConstValues.FunctionId.ConferenceNews, RoleType.修改))
							{
								<text>
					    			strInfo += "<a href='#' style='color:#66CDAA;font-weight:bold;text-decoration:underline;' onclick='editData(\""
									+ rec.id + "\")'>@Resources.Modify</a>";
					    			</text>
							}
					    		@if ((User as ICISPrincipal).IsSSA || (User as ICISPrincipal).CSAList.Contains(Model.ConferenceId) || Utility.HasConferenceRole((User as ICISPrincipal), Model.ConferenceId, ConstValues.FunctionId.ConferenceNews, RoleType.删除))
							{
								<text>
					    			if (strInfo != "") {
					    				strInfo += "&nbsp;|&nbsp;";
					    			}
					    			strInfo += "<a href='#' style='color:#DC143C;font-weight:bold;text-decoration:underline;' onclick='deleteData(\""
									+ rec.id + "\",\"" + tmp + "\")'>@Resources.Delete</a>";
					    			</text>
							}
					    		return strInfo;
						}
					},
					</text>
				}
				{
					field: "newsTitle", title: "@Resources.NewsTitle", align: "center", sortable: true, width: 150,
					formatter: function (value, rec) {
	                			var conStr = ""
	                			if (rec.status == "@ConstValues.Status.正常") {
	                				if (rec.link	!="") {
	                					conStr += "<a href='" + rec.link + "' style='color:#1874CD;text-decoration:underline;' target='_blank'>" + value + "</a>  ";
	                					return conStr;
	                				} else {
	                					return value;
	                				}
	                			} else {
	                				return value;
	                			}
					}
				},
			]],
			columns: [[
				{ field: "newsListId", title: "@Resources.NewsListName", align: "center", sortable: true, width: 200 },
				{ field: "keyword", title: "@Resources.Keyword", align: "center", sortable: true, width: 200 },
				{
					field: "simplePic", title: "@Resources.SimplePic", align: "center", sortable: true, width: 150,
			    		formatter: function (value, rec) {
			    			if (value!=null && value != "") {
			    				var link = "";
			    				link +="<img id='img' style='height: 60px; width: 80px' src='@Url.Action(nameof(ConferenceNewsController.ShowPic),nameof(ConferenceNewsController).GetControllerName())"+"/"+ rec.id + "?random=" + Math.random() + "' />";
			    				return link;
			    			} else {
			    				return "@ConstValues.strHyphen@ConstValues.strHyphen"
			    			}
			    		}
				},
				{
					field: "mainPic", title: "@Resources.MainPic", align: "center", sortable: true, width: 150,
			    		formatter: function(value, rec) {
			    			if (value!=null) {
			    				var strInfo = "";
			    				strInfo += "<a href='#' style='color:#66CDAA;font-weight:bold;text-decoration:underline;' onclick='showImg(\""
								+ rec.id + "\")'>@Resources.MainPic</a>";
			    				return strInfo;
			    			} else {
			    				return "@ConstValues.strHyphen@ConstValues.strHyphen"
			    			}
			    		}
				},
				{ field: "showTime", title: "@Resources.ShowTime", align: "center", sortable: true, width: 150 },
				{
					field: "recommendation", title: "@Resources.IsRecommend", align: "center", sortable: true, width: 150,
			    		formatter: function(value, rec) {
			    			if (value == true) {
			    				return "@Resources.Yes";
			    			} else {
			    				return "@Resources.No";
			    			}
			    		}
				},
				{
					field: "stick", title: "@Resources.IsTop", align: "center", sortable: true, width: 150,
			    		formatter: function(value, rec) {
			    			if (value == true) {
			    				return "@Resources.Yes";
			    			} else {
			    				return "@Resources.No";
			    			}
			    		}
				},
				{
					field: "mobileShow", title: "@Resources.IsShowInMobile", align: "center", sortable: true, width: 150,
			    		formatter: function(value, rec) {
			    			if (value == true) {
			    				return "@Resources.Yes";
			    			} else {
			    				return "@Resources.No";
			    			}
			    		}
				},
				{ field: "viewCount", title: "@Resources.BrowseTimes", align: "center", sortable: true, width: 150 },
				{ field: "link", title: "@Resources.Link", align: "center", sortable: true, width: 300 },
				{
					field: "status", title: "@Resources.Status", align: "center", sortable: true, width: 100,
			    		formatter: function(value, rec) {
			    			if (value=="@ConstValues.Status.正常") {
			    				return "@Resources.Normal"
			    			} else {
			    				return "@Resources.Pause"
			    			}
			    		}
				},
				{ field: "sort", title: "@Resources.Sort", align: "center", sortable: true, width: 100 },
				{ field: "remark", title: "@Resources.Remark", align: "center", sortable: true, width: 200 },
				{ field: "creator", title: "@Resources.Creator", align: "center", sortable: true, width: 100 },
				{ field: "createIP", title: "@Resources.CreateIP", align: "center", sortable: true, width: 150 },
				{ field: "createDate", title: "@Resources.CreateDate", align: "center", sortable: true, width: 150 },
			]],
			onBeforeLoad: function(param) {
				param.random = Math.random();
				param.conferenceId = $("#hidConferenceId").val();
			}
		});

		$(window).resize(function () {
			$("#dataGrid").datagrid("resize", {
				width: $(window).width() - 285,
				height: $(window).height() - 110
			});
		});

		$("#detailWindow").window({
			onOpen: function () {
				$(this).scrollTop(0);
			},
			width: $(window).width() - 285,
			height: $(window).height() - 110,
			left: ($(window).width() - windowWidth) * 0.5,
			top: ($(window).height() - windowHeight) * 0.5
		});

		var orgCount = 0;
		$("#txtNewsListName").combobox({
			editable: false,
			required:true,
			valueField: "id",
			textField: "name",
			url: "@Url.Action(nameof(UtilityController.GetNewsList), nameof(UtilityController).GetControllerName())"+"/"+"@Model.ConferenceId",
			onLoadSuccess: function(data) {
				orgCount = data.length;
			},
			onShowPanel: function () {
				if (orgCount < 10) {
					$(this).combobox("panel").height("auto");
				} else {
					$(this).combobox("panel").height(200);
				}
			},
			onBeforeLoad: function(param) {
				param.conferenceId = $("#hidConferenceId").val();
				param.random = Math.random();
			},
		});
	});

	function deleteData(id,mailServer) {
		var confirmMessage = "@Resources.CfmDelete";
		confirmMessage = confirmMessage.replace(/\{0\}/g, mailServer);
		$.messager.confirm("@Resources.Delete", confirmMessage, function (r) {
			if (r) {
				$("#hidID").val(id);
				$.post("@Url.Action(nameof(ConferenceNewsController.Delete),
						nameof(ConferenceNewsController).GetControllerName(),new { ConferenceId = Model.ConferenceId })",
					$("#frmDetail").serialize(),
					function(data, textStatus, jqXHR) {
						if (data.result == "@ConstValues.AjaxFailResult") {
				    			common.showError(data.message);
						} else {
				    			common.showSuccess(data.message, true);
				    			$("#dataGrid").datagrid("reload");
						}
					}
				);
			}
		});
	};

	function addData() {
		$("#hdnWindowType").val("add");
		$("#detailWindowTitle").text("@Resources.Create");
		$("#txtSort").numberbox("setValue", @ConstValues.DefaultSort);
		$("#txtNewsTitle").textbox("setValue","");
		$("#txtNewsListName").combobox("setValue","");
		$("#txtSimplePic").filebox("clear");
		$("#hidSimplePic").val("");
		$("#txtMainPic").filebox("clear");
		$("#txtMainPic").val("");
		$("#ddlIsRecommend").combobox("setValue","@ConstValues.GenericSelectionType.无");
		$("#ddlIsTop").combobox("setValue","@ConstValues.GenericSelectionType.无");
		$("#ddlIsShowInMobile").combobox("setValue","@ConstValues.GenericSelectionType.无");
		CKEDITOR.instances.editor.setData("");
		CKEDITOR.instances.editorSec.setData("");
		$("#showTime").datebox("setValue","today");
		$("#txtLink").textbox("setValue","");
		$("#txtKeyword").textbox("setValue","");

		$("#txtRemark").textbox("setValue","");
		$("#detailWindow").window("open");
	}

	function editData(id) {
		var url = "@Url.Action(nameof(ConferenceNewsController.GetEditData),
				nameof(ConferenceNewsController).GetControllerName())" + "/" + id;
		$.get(url, null, function (data, textStatus, jqXHR) {
			if (data.result == "@ConstValues.AjaxFailResult") {
				common.showError(data.message);
				$("#dataGrid").datagrid("reload");
			} else {
				$("#txtNewsTitle").textbox("setValue",data.data.newsTitle);
				$("#txtNewsListName").combobox("setValue",data.data.newsListId);
				$("#txtSimplePic").filebox("clear");
				$("#txtSimplePic").filebox("setText",data.data.simplePic);
				$("#hidSimplePic").val(data.data.simplePic);
				$("#txtMainPic").filebox("clear");
				$("#txtMainPic").filebox("setText",data.data.mainPic);
				$("#hidMainPic").val(data.data.mainPic);
				$("#ddlIsRecommend").combobox("setValue",data.data.recommendation);
				$("#ddlIsTop").combobox("setValue",data.data.stick);
				$("#ddlIsShowInMobile").combobox("setValue",data.data.mobileShow);
				$("#showTime").datebox("setValue",data.data.showTime);
				$("#txtLink").textbox("setValue",data.data.link);
				$("#txtKeyword").textbox("setValue",data.data.keyword);
				CKEDITOR.instances.editor.setData(data.data.abstract);
				CKEDITOR.instances.editorSec.setData(data.data.mainText);
				$("#ddlStatus").combobox("setValue",data.data.status);
				$("#txtSort").numberbox("setValue", data.data.sort);
				$("#txtRemark").textbox("setValue",data.data.remark);
				$("#hidID").val(id);
				$("#hdnWindowType").val("edit");
				$("#detailWindowTitle").text("@Resources.Modify");
				$("#detailWindow").window("open");
			}
		});
	}

	function saveData() {
		var isValid = $("#frmDetail").form("validate");
		var imgEnd = $("#txtMainPic").filebox("getText");
		var simEnd = $("#txtSimplePic").filebox("getText");
		if (isValid) {
			if (imgEnd!= "" && !/\.(gif|jpg|jpeg|png|GIF|JPG|PNG|JPEG)$/.test(imgEnd)) {
				common.showError("@Resources.MsgImgType");
				return false;
			}
			if (simEnd!= "" && !/\.(gif|jpg|jpeg|png|GIF|JPG|PNG|JPEG)$/.test(simEnd)) {
				common.showError("@Resources.MsgImgType");
				return false;
			}
			$.messager.confirm("@Resources.Save", "@Resources.CfmSave", function (r) {
				if (r) {
					var loading = layer.load(0,  {
						shade: [0.4,"#fff"]
					});

					if($("#hdnWindowType").val()=="add") {
						$("#frmDetail").form({
							iframe: false,
							success: function (data) { }
						});

						$("#txtAbstract").val(CKEDITOR.instances.editor.getData());
						$("#txtNewsEssay").val(CKEDITOR.instances.editorSec.getData());
						$("#frmDetail").form("submit", {
							url: "@Url.Action(nameof(ConferenceNewsController.Create), nameof(ConferenceNewsController).GetControllerName(),
								new { ConferenceId = Model.ConferenceId })",
							onSubmit: function (param) {
								param.random = Math.random();
							},
							success: function (data) {
								layer.close(loading);
								data = JSON.parse(data);
								if (data.result == "@ConstValues.AjaxFailResult") {
									common.showError(data.message);
								} else {
									common.showSuccess(data.message, true);
									$("#detailWindow").window("close");
									$("#dataGrid").datagrid("reload");
								}
							},
						});
					} else if ($("#hdnWindowType").val()=="edit") {
						$("#frmDetail").form({
							iframe: false,
							success: function (data) { }
						});

						$("#txtAbstract").val(CKEDITOR.instances.editor.getData());
						$("#txtNewsEssay").val(CKEDITOR.instances.editorSec.getData());
						$("#frmDetail").form("submit", {
							url: "@Url.Action(nameof(ConferenceNewsController.Modify), nameof(ConferenceNewsController).GetControllerName(),
								new { ConferenceId = Model.ConferenceId })",
							onSubmit: function (param) {
								param.random = Math.random();
							},
							success: function (data) {
								layer.close(loading);
								data = JSON.parse(data);
								if (data.result == "@ConstValues.AjaxFailResult") {
									common.showError(data.message);
								} else {
									common.showSuccess(data.message, true);
									$("#detailWindow").window("close");
									$("#dataGrid").datagrid("reload");
								}
							},
						});
					}
				}
			})
		}
	};

	function searchData() {
		$("#dataGrid").datagrid("load", {
			selNewsTitle: $("#selNewsTitle").textbox("getValue"),
		});
	}

	function showImg(id) {
		var url = "@Url.Action(nameof(ConferenceNewsController.ShowMain),
				nameof(ConferenceNewsController).GetControllerName())"+"?id="+id;
		$.get(url, null, function (data, textStatus, jqXHR) {
			$("#dialogMsg").setApDiv({
				width: 1200,
				height: 800,
				html: data,
			});
		});
	}
</script>
}